function count_same_elements(collection) {
  let object={};
  let arr=[];
  for(let i of collection){
    if(!object[i]){
      object[i]={};
      object[i].key=i;
      object[i].count=1;
    }
    else {
      object[i].count++;
    }
  }
  for(let j in object){
    arr.push(object[j]);
  }
  return arr;
}

module.exports = count_same_elements;
